package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

/*
	defer类似栈,是先进后出的顺序
	何时使用defer：
		1、Open/Close
		2、Lock/Unlock
		3、PrintHeader/PrintFooter
*/
func main() {
	writerFile("./go-base/test.txt")
}

func writerFile(filePath string) {
	file, err := os.Create(filePath)
	if err != nil {
		panic("open file Error!!!")
	}
	defer file.Close()

	writer := bufio.NewWriter(file)
	defer writer.Flush()

	for i := 0; i < 20; i++ {
		writer.WriteString(strconv.Itoa(i) + ",")
	}
	fmt.Println("writer successful!!!")
}
